package webExperiment;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

//-----------------------------------------------------
public class FreeQuestion extends JPanel {
    /**
	 * 
	 */
    private static final long serialVersionUID = 1L;
    public static int width = 450;
    public static int widthInput = width;
    public static int height = 70;
    public static int heightText = 30;
    private JTextArea quest = new JTextArea();
    private JTextField input = new JTextField();

    public FreeQuestion(Color bgColor) {
	this(bgColor, false);
    }

    public FreeQuestion(Color bgColor, boolean createLineBorder) {
	this.setPreferredSize(new Dimension(width, height));
	this.setBackground(bgColor);
	this.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 5));
	if (createLineBorder)
	    this.setBorder(BorderFactory.createLineBorder(Color.lightGray));

	input.setPreferredSize(new Dimension(widthInput - 20, 25));
	quest.setPreferredSize(new Dimension(width - 10, heightText));
	quest.setEditable(false);
	quest.setLineWrap(true);
	quest.setWrapStyleWord(true);
	quest.setFont(new Font("Arial", Font.BOLD, 12));
	quest.setBackground(bgColor);
	setQuestionColor(Color.BLACK);

	this.add(quest);
	this.add(input);
    }

    public void writeLabels(String questStr) {
	if (questStr.length() > 0) {
	    quest.setText(questStr);
	    this.setVisible(true);
	} else {
	    setVisible(false);
	}
	input.setText("");
    }

    public void setQuestionColor(Color fg) {
	quest.setForeground(fg);
    }

    public String getAnswer() {
	return input.getText();
    }

}// end class (long)
